﻿#nullable enable

using System;
using System.Collections.Concurrent;

namespace PHMEE.EnergyEfficiency;

public static class FuelCfMapper
{
    private static readonly ConcurrentDictionary<FuelType, float> CO2CfDictionary;
    
    private static readonly ConcurrentDictionary<FuelType, float> CH4CfDictionary;
    
    private static readonly ConcurrentDictionary<FuelType, float> N2OCfDictionary;

    static FuelCfMapper()
    {
        CO2CfDictionary = new ConcurrentDictionary<FuelType, float>
        {
            [FuelType.MDO] = 3.206F,
            [FuelType.MGO] = 3.206F,
            [FuelType.LFO] = 3.151F,
            [FuelType.HFO] = 3.114F,
            [FuelType.LPGP] = 3.000F,
            [FuelType.LPGB] = 3.030F,
            [FuelType.LNG] = 2.755F, // 原值为 2.750，20240613 修改为 2.755，因完善 MRV 报表时邱工查阅了资料
            [FuelType.Methanol] = 1.375F,
            [FuelType.Ethanol] = 1.913F,
            [FuelType.LSHFO] = 3.114F,
            [FuelType.LSLFO] = 3.151F,
            [FuelType.LSMGO] = 3.206F,
            [FuelType.ULSFO2020] = 3.114F,
            [FuelType.ULSLFO2020] = 3.151F,
            [FuelType.ULSMDO2020] = 3.206F,
            [FuelType.ULSMGO2020] = 3.206F,
            [FuelType.VLSFO2020] = 3.206F, // 原值为 3.114，20240613 修改为 3.206，因完善 MRV 报表时邱工查阅了资料
            [FuelType.VLSLFO2020] = 3.151F,
        };
        
        N2OCfDictionary = new ConcurrentDictionary<FuelType, float>
        {
            [FuelType.MDO] = 0.00018F,
            [FuelType.MGO] = 0.00018F,
            [FuelType.LFO] = 0.00018F,
            [FuelType.HFO] = 0.00018F,
            [FuelType.LPGP] = 0F, // TBM，未测定
            [FuelType.LPGB] = 0F, // TBM，未测定
            [FuelType.LNG] = 0.00011F,
            [FuelType.Methanol] = 0F, // TBM，未测定
            [FuelType.Ethanol] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.LSHFO] = 0.00018F,
            [FuelType.LSLFO] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.LSMGO] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSFO2020] = 0.00018F,
            [FuelType.ULSLFO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSMDO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSMGO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.VLSFO2020] = 0.00018F,
            [FuelType.VLSLFO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
        };
        
        CH4CfDictionary = new ConcurrentDictionary<FuelType, float>
        {
            [FuelType.MDO] = 0.00005F,
            [FuelType.MGO] = 0.00005F,
            [FuelType.LFO] = 0.00005F,
            [FuelType.HFO] = 0.00005F,
            [FuelType.LPGP] = 0F, // TBM，未测定
            [FuelType.LPGB] = 0F, // TBM，未测定
            [FuelType.LNG] = 0F,
            [FuelType.Methanol] = 0F, // TBM，未测定
            [FuelType.Ethanol] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.LSHFO] = 0.00005F,
            [FuelType.LSLFO] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.LSMGO] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSFO2020] = 0.00005F,
            [FuelType.ULSLFO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSMDO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.ULSMGO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
            [FuelType.VLSFO2020] = 0.00005F,
            [FuelType.VLSLFO2020] = 0.000F, // 查不到，暂时当 0 处理，在用到之前会作为 TBM，未测定，报表中输出的结果均会为 N/A
        };
        

    }

    public static float GetFuelCfCO2(FuelType fuelType)
    {
        if (!CO2CfDictionary.TryGetValue(fuelType, out var value))
        {
            throw new Exception($"油品的 Cf 不存在：FuelType {fuelType}");
        }
        
        return value;
    }
    
    public static float GetFuelCfCH4(FuelType fuelType)
    {
        if (!CH4CfDictionary.TryGetValue(fuelType, out var value))
        {
            throw new Exception($"油品的 Cf 不存在：FuelType {fuelType}");
        }
        
        return value;
    }
    
    public static float GetFuelCfN2O(FuelType fuelType)
    {
        if (!N2OCfDictionary.TryGetValue(fuelType, out var value))
        {
            throw new Exception($"油品的 Cf 不存在：FuelType {fuelType}");
        }
        
        return value;
    }
}